package com.aseo.business.hibernate;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

import org.springframework.stereotype.Service;

import com.aseo.exception.ConstraintViolationException;
import com.aseo.model.dao.Dao;
import com.aseo.model.entity.hibernate.TrayectoRuta;

@Service
public class TrayectoRutaManager implements ManagerInterface<TrayectoRuta> {

	@Resource
	private Dao dao;

	@Override
	public List<TrayectoRuta> getAll() {
		final List<TrayectoRuta> list = dao.find(TrayectoRuta.class);
		return list;
	}

	@Override
	public void persist(TrayectoRuta t) {
		dao.persist(t);
	}

	public void validate(TrayectoRuta trayectoRuta)
			throws ConstraintViolationException {

		Set<ConstraintViolation<TrayectoRuta>> constraintViolations = dao
				.validate(trayectoRuta);

		for (ConstraintViolation<TrayectoRuta> constraintViolation : constraintViolations) {
			throw new ConstraintViolationException(constraintViolation
					.getMessage());
		}

	}

}
